<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/9
  Time: 12:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>

        table {
            border: 1px solid;
        }

        td {
            border: 1px solid;
        }

        div {
            display: flex;
            justify-content: center;
            align-items: center;
        }

    </style>
    <base href="${pageContext.request.contextPath}/">
    <script src="js/jQuery3.6.0.js"></script>
</head>
<body>
<form action="CardServeltAdd">
<div>
    <table>
        <tr>
            <td colspan="2"><h1>添加组织机构信息</h1></td>
        </tr>
        <tr>
            <td><span>组织机构名称（*）：</span></td>
            <td><input id="name" name="name" onblur="add(this.value)" type="text">
                <sapn id="span1"></sapn>
            </td>

        </tr>
        <tr>
            <td>负责人（*）</td>
            <td><input id="principalName" name="principalName" type="text" ></td>
        </tr>
        <tr>
            <td><span>创建日期：</span></td>
            <td><input id="createDate" name="createDate" onblur="date(this.value)" type="text">
                <sapn id="span2"></sapn>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center"><input type="button" onclick="adds()" value="提交"><input type="button" value="返回"></td>
        </tr>
    </table>
</div>
</form>
</body>
<script>
    function date(date){
        var a=/^\d{4}-\d{2}-\d{2}$/
        if (!a.test(date)){
            alert("日期格式不正确")
        }
    }
    function add(name) {
        $.ajax({
            url: '${pageContext.request.contextPath}/OrgnazitonServletName',
            type: 'get',
            data: "name=" + name,
            dataType: 'text',
            success: function (data) {
                if (data == "true") {
                    $("#span1").html('该组织机构已存在')
                } else {
                    $("#span1").html('')
                }
            }
        })
    }
    function adds(){
        let name = document.getElementById("name").value
        let  principalName= document.getElementById("principalName").value
        let data = document.getElementById("createDate").value
        let a= $("#span1").innerHTML
        if (name == '' || principalName == '' || data == '' ) {
            alert("图书名称和作者名称不能为空")
        }else {
            location.href = "${pageContext.request.contextPath}/OrgnazitionServletAdd?name="+name+"&principalName="+principalName+"&data="+data
        }
    }
</script>
</html>
